package com.study.rwdb;

/**
 * @author: chenhs
 * @date: Created in 16:08 2020/2/21
 **/
public final class DynamicDataSourceHolder {

    private static final ThreadLocal<DynamicDataSourceGlobal> holder = new ThreadLocal<>();


    private DynamicDataSourceHolder(){}

    /**
     * 设置数据源
     * @param dataSource
     */
    public static void putDataSource(DynamicDataSourceGlobal dataSource) {
        holder.set(dataSource);
    }

    /**
     * 获取数据源
     * @return
     */
    public static DynamicDataSourceGlobal getDataSource(){
        return holder.get();
    }

    /**
     * 清理数据源
     */
    public static void clearDataSource() {
        holder.remove();
    }
}
